<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.w3.org/1999/xhtml">
<head>
    <th:block th:include="include :: header('附件列表')"/>
    <style type="text/css">
    		*{padding: 0;margin:0;}
    		.upfile{width: 100px;height: 36px;border-radius: 3px;color: #fff;text-align: center;line-height: 36px;background: #19aa8d;margin:20px;border: 0;cursor: pointer;}
    		.upfile:hover{opacity: 0.8;}
    		.zwsj{width: 100%;text-align: center;}
    		.oImg{
                    width: 90px;
                    height: 90px;
                    background-color: #F33;
                    /*position:absolute;*/
                    left:0px;
                    top:0px;
                    z-index:1;
                }
                .oImg:hover{
                    background-color:#0CF;
                    width:200px; height:195px;
                    position: absolute;
                    z-index:100;

                }
    	</style>

</head>
<body class="gray-bg">
    <div class="container-div">
        <div class="wrapper wrapper-content">
            <div class="row">
                <!--<div class="col-sm-3">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <div class="file-manager">
                                <h5>显示：</h5>
                                <a href="file_manager.html#" class="file-control active">所有</a>
                                <a href="file_manager.html#" class="file-control">文档</a>
                                <a href="file_manager.html#" class="file-control">视频</a>
                                <a href="file_manager.html#" class="file-control">图片</a>
                                <div class="hr-line-dashed"></div>
                                <button class="btn btn-primary btn-block">上传文件</button>
                                <div class="hr-line-dashed"></div>
                                <h5>文件夹</h5>
                                <ul class="folder-list" style="padding: 0">
                                    <li><a href="file_manager.html"><i class="fa fa-folder"></i> 文件</a>
                                    </li>
                                    <li><a href="file_manager.html"><i class="fa fa-folder"></i> 图片</a>
                                    </li>
                                    <li><a href="file_manager.html"><i class="fa fa-folder"></i> Web页面</a>
                                    </li>
                                    <li><a href="file_manager.html"><i class="fa fa-folder"></i> 插图</a>
                                    </li>
                                    <li><a href="file_manager.html"><i class="fa fa-folder"></i> 电影</a>
                                    </li>
                                    <li><a href="file_manager.html"><i class="fa fa-folder"></i> 书籍</a>
                                    </li>
                                </ul>
                                <h5 class="tag-title">标签</h5>
                                <ul class="tag-list" style="padding: 0">
                                    <li><a href="file_manager.html">爱人</a>
                                    </li>
                                    <li><a href="file_manager.html">工作</a>
                                    </li>
                                    <li><a href="file_manager.html">家庭</a>
                                    </li>
                                    <li><a href="file_manager.html">孩子</a>
                                    </li>
                                    <li><a href="file_manager.html">假期</a>
                                    </li>
                                    <li><a href="file_manager.html">音乐</a>
                                    </li>
                                    <li><a href="file_manager.html">照片</a>
                                    </li>
                                    <li><a href="file_manager.html">电影</a>
                                    </li>
                                </ul>
                                <div class="clearfix"></div>
                            </div>
                        </div>
                    </div>
                </div>-->
                <div class="col-sm-12 animated fadeInRight">
                    <button id="upFile" class="upfile" onclick="subFiles()"
                        shiro:hasPermission="system:attachment:edit">上传</button>
                    <div class="row">
                        <div class="col-sm-12" id="attachmentTile">
                            <!--<div class="file-box">
                                <div class="file">
                                    <a href="file_manager.html#">
                                        <span class="corner"></span>

                                        <div class="icon">
                                            <i class="fa fa-file"></i>
                                        </div>
                                        <div class="file-name">
                                            Document_2014.doc
                                            <br/>
                                            <small>添加时间：2014-10-13</small>
                                        </div>
                                    </a>
                                </div>
                            </div>-->
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
<th:block th:include="include :: footer" />
<script th:src="@{/dckj/js/attachment.js}"></script>
<script th:inline="javascript">
    var viewFlag = [[${@permission.hasPermi('system:sysAttachment:view')}]];
    var removeFlag = [[${@permission.hasPermi('system:sysAttachment:edit')}]];
    var prefix = ctx + "system/attachment";
    var mainId = [[${mainId}]];
    var entityName = [[${entityName}]];
    var isView = [[${isView}]];

    $(function () {
        init();
        if (isView == 1) {
            $("#upFile").hide();
        } else {
            $("#upFile").show();
        }
    });

    //初始化
    function init() {
        var url = prefix + "/list";
        var data = {"mainId": mainId, "entityName": entityName, "viewMode":"viewMode"};
        $.operate.post(url, data, showTile);
    }

    //回显
    function showTile(result) {
        var htm = '<div class="zwsj"><img src="'+ctx+'images/zwsj.png"></div>';
        if (result.code == web_status.SUCCESS) {
            var data = result.rows;
            if (data != null && data != undefined && data.length > 0) {
                var htm = "";
                for (var i = 0; i < data.length; i++) {
                    var row = data[i];
                    htm += "<div class='file-box'>" +
                                "<a href='#' onclick='previewFile(\""+row.attachmentPath+"\")'>" +
                                    "<div class='file'>" +
                                        "<span class='corner'></span>" +
                                            "<div class='icon'>";
                                            if (row.attachmentType == "jpg" || row.attachmentType == "png" || row.attachmentType == "gif") {
                                                /*htm += "<img class='oImg' src='"+ctx+"profile/upload/"+row.attachmentPath+"'" +
                                                    "alt='"+row.attachmentName+"' title='"+row.attachmentName+"'>";*/
                                                htm += "<img class='oImg' src="+$.operate.getPreviewUrl(row.attachmentPath)+">";
                                            } else {
                                                htm += "<i class='fa fa-bar-chart-o'></i>";
                                            }
                                            htm += "</div>" +
                                                "<div class='file-name'>" +
                                                "<a href='#' style=' width: 180px; overflow: hidden;text-overflow:ellipsis;  " +
                                                 "white-space: nowrap;display: inline-block;' title='"+row.attachmentName+"'" +
                                                  "onclick='downloadFileById(\""+row.id+"\")'>"+row.attachmentName+"</a>" +
                                                "<br/>" +
                                                "<small>添加时间："+row.uploadDate+"</small>" +
                                                "<br/>" +
                                                "<small>上传人："+row.createByName+"</small>" +
                                                "<br/>" +
                                                "<small>文件大小："+$.common.calculateFileSize(row.attachmentSize)+"</small>";
                                                if (isView == 0) {
                                                   htm += "<a href='#' class='fa fa-remove' style='float:right;font-size:20px;color:red;' " +
                                                      "onclick='removeFile(\""+row.id+"\",\""+row.attachmentName+"\")'></a>";
                                                }
                                             htm += "</div>" +
                                    "</div>" +
                                "</a>" +
                            "</div>";
                }
            }
        } else  {
            $.modal.alertError(result.msg);
        }
        $("#attachmentTile").html(htm);
        $.modal.closeLoading();
    }

    //上传文件
    function subFiles() {
        var url = prefix + "/add?mainId="+mainId+"&entityName="+entityName;
         $.modal.open("上传附件", url, "", "","");
    }
    function removeFile(id,attachmentName) {
      $.modal.confirm("确认要删除 " + attachmentName + " 数据吗?", function () {
                  var url = prefix + "/remove";
                  var data = {"ids": id};
                  $.operate.submit(url, "post", "json", data, init);
              });
    }
</script>
</body>
</html>